package com.yq.cp.service.yw.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.yq.cp.config.UserThreadLocal;
import com.yq.cp.entity.basics.InspectionItemManagementExtend;
import com.yq.cp.entity.basics.Message;
import com.yq.cp.entity.basics.model.SiteHeaderToUser;
import com.yq.cp.entity.common.PageVo;
import com.yq.cp.entity.permission.User;
import com.yq.cp.entity.yw.*;
import com.yq.cp.entity.yw.dto.YwGdxxDochuDto;
import com.yq.cp.entity.yw.vo.YwGdxxVo;
import com.yq.cp.mapper.basics.InspectionItemManagementExtendMapper;
import com.yq.cp.mapper.basics.MessageMapper;
import com.yq.cp.mapper.permission.UserMapper;
import com.yq.cp.mapper.yw.*;
import com.yq.cp.service.basics.OrganizationalStructureService;
import com.yq.cp.service.yw.YwGdxxCljlService;
import com.yq.cp.service.yw.YwGdxxService;
import com.yq.cp.utils.DateTimeUtil;
import com.yq.cp.utils.PdfPageUtil;
import com.yq.cp.utils.UrlConvertUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 运维-工单信息 服务实现类
 * </p>
 *
 * @author zh
 * @since 2024-09-07
 */
@Service
@Transactional
public class YwGdxxServiceImpl extends ServiceImpl<YwGdxxMapper, YwGdxx> implements YwGdxxService {

    @Resource
    YwGdxxMapper ywGdxxMapper;
    @Resource
    YwZbglGlryMapper ywZbglGlryMapper;
    @Resource
    YwGdxxCljlMapper ywGdxxCljlMapper;
    @Resource
    InspectionItemManagementExtendMapper inspectionItemManagementExtendMapper;
    @Resource
    MessageMapper messageMapper;
    @Resource
    UserMapper userMapper;
    @Resource
    YwGdxxNzjlMapper ywGdxxNzjlMapper;
    @Resource
    YwBjglMapper ywBjglMapper;

    @Resource
    OrganizationalStructureService organizationalStructureService;

    @Resource
    YwGdxxCljlService ywGdxxCljlService;
    @Resource
    UrlConvertUtil urlConvertUtil;
    @Resource
    YwGdxxClNzjlMapper ywGdxxClNzjlMapper;

    @Override
    public void add(YwGdxx ywGdxx) {
        Long userId = UserThreadLocal.get().getId();
        ywGdxx.setSqrId(userId);
        ywGdxx.setFzrAuditState(0);
        ywGdxx.setZzAuditState(0);
        ywGdxx.setState(0);
        ywGdxx.setNzzt(0);
        ywGdxx.setHxzt(null);
        ywGdxx.setGdly(1);
        ywGdxxMapper.insert(ywGdxx);

        QueryWrapper<YwZbglGlry> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("gl_id",ywGdxx.getXqId());
        List<YwZbglGlry> ywZbglGlries = ywZbglGlryMapper.selectList(queryWrapper);
        for (int i = 0; i < ywZbglGlries.size(); i++) {
            YwZbglGlry ywZbglGlry = ywZbglGlries.get(i);
            ywZbglGlry.setId(null);
            ywZbglGlry.setFl(4);
            ywZbglGlry.setGlId(ywGdxx.getId());
            ywZbglGlryMapper.insert(ywZbglGlry);
        }
    }

    @Override
    public void sc(YwGdxx ywGdxx) {
        ywGdxxMapper.sc(ywGdxx.getId());
    }

    @Override
    public void audit1(YwGdxx ywGdxx) {
        Long userId = UserThreadLocal.get().getId();
        YwGdxx ywGdxx1 = ywGdxxMapper.selectById(ywGdxx.getId());
        if (ywGdxx1!=null){
//            ywGdxx1.setState(ywGdxx.getAuditState());
            ywGdxx1.setFzrAuditState(ywGdxx.getAuditState());
            ywGdxx1.setFzrAuditExcuse(ywGdxx.getAuditExcuse());
            ywGdxx1.setFzrAuditTime(DateTimeUtil.dqsj());
            ywGdxx1.setFzrAuditUserId(userId);
            ywGdxxMapper.updateById(ywGdxx1);
        }
    }

    @Override
    public void audit2(YwGdxx ywGdxx) {
        Long userId = UserThreadLocal.get().getId();
        YwGdxx ywGdxx1 = ywGdxxMapper.selectById(ywGdxx.getId());
        if (ywGdxx1!=null){
            ywGdxx1.setState(ywGdxx.getAuditState());
            ywGdxx1.setZzAuditState(ywGdxx.getAuditState());
            ywGdxx1.setZzAuditExcuse(ywGdxx.getAuditExcuse());
            ywGdxx1.setZzAuditTime(DateTimeUtil.dqsj());
            ywGdxx1.setZzAuditUserId(userId);
            if (ywGdxx1.getZzAuditState()==1){
                ywGdxx1.setHxzt(1);
            }
            ywGdxxMapper.updateById(ywGdxx1);

            if (ywGdxx1.getZzAuditState()==1){
                QueryWrapper<YwZbglGlry> queryWrapper=new QueryWrapper<>();
                queryWrapper.eq("gl_id",ywGdxx1.getId());
                queryWrapper.eq("fl",4);
                queryWrapper.in("type",1,3);

                List<YwZbglGlry> ywZbglGlries = ywZbglGlryMapper.selectList(queryWrapper);
                for (int i = 0; i < ywZbglGlries.size(); i++) {
                    YwZbglGlry ywZbglGlry = ywZbglGlries.get(i);
                    Message message=new Message();
                    message.setUserId(ywZbglGlry.getUserId());
                    message.setType(1);
                    message.setIsReceive(0);
                    message.setTitle("尊敬的用户，有新的工单已设置，请尽快接单并处理。");
                    messageMapper.insert(message);
                }
            }
        }
    }

    @Override
    public IPage<YwGdxx> page(YwGdxxVo vo) {

        IPage<YwGdxx> ipage=new Page<>(vo.getPage(),vo.getSize());
        if (vo.getRq()!=null && !vo.getRq().equals("")){
            vo.setBeginTime(DateTimeUtil.toSimpleDateTime(vo.getRq()+" 00:00:00"));
            vo.setOverTime(DateTimeUtil.toSimpleDateTime(vo.getRq()+" 23:59:59"));
        }
        ywGdxxMapper.page(ipage,vo);
        for (int i = 0; i < ipage.getRecords().size(); i++) {

            YwGdxx ywGdxx = ipage.getRecords().get(i);

            if (ywGdxx.getClrId()!=null && ywGdxx.getClrId().compareTo(UserThreadLocal.get().getId())==0){
                ipage.getRecords().get(i).setSfngjsyj(1);
            }else {
                ipage.getRecords().get(i).setSfngjsyj(0);
            }
            if (ywGdxx.getClrId()==null){
                ipage.getRecords().get(i).setSfngjsyj(0);
            }

            Long cxsfwyg = userMapper.cxsfwyg(ywGdxx.getNyzId(), UserThreadLocal.get().getId());
            Long cxsfwfzr = userMapper.cxsfwfzr(ywGdxx.getNyzId(), UserThreadLocal.get().getId());
            Long cxsfwzz = userMapper.cxsfwzz(ywGdxx.getNyzId(), UserThreadLocal.get().getId());

            QueryWrapper<YwGdxxNzjl> queryWrapper=new QueryWrapper<>();
            queryWrapper.eq("gdxx_id",ipage.getRecords().get(i).getId());
            queryWrapper.orderByDesc("id");
            boolean exists = ywGdxxNzjlMapper.exists(queryWrapper);
            List<YwGdxxNzjl> ywGdxxNzjls = ywGdxxNzjlMapper.selectList(queryWrapper);
            if (exists){
                YwGdxxNzjl nzjl = ywGdxxNzjls.get(0);
                if (nzjl.getNzrId().compareTo(UserThreadLocal.get().getId())==0 && nzjl.getAuditState()==1){
                    ipage.getRecords().get(i).setSfnjxnz(1);
                }else {
                    ipage.getRecords().get(i).setSfnjxnz(0);
                }
//                ipage.getRecords().get(i).setSfnjxnz(0);
            }else {
                if (cxsfwfzr.intValue()>0){
                    ipage.getRecords().get(i).setSfnjxnz(cxsfwfzr.intValue());
                    QueryWrapper<YwZbglGlry> queryWrapper1=new QueryWrapper<>();
                    queryWrapper1.eq("gl_id",ywGdxx.getId());
                    queryWrapper1.eq("type",1);
                    queryWrapper1.eq("fl",4);
                    List<YwZbglGlry> ywZbglGlries = ywZbglGlryMapper.selectList(queryWrapper1);
                    for (int j = 0; j < ywZbglGlries.size(); j++) {
                        Long userId = ywZbglGlries.get(j).getUserId();
                        if (userId.compareTo(UserThreadLocal.get().getId())==0){
                            ipage.getRecords().get(i).setSfnjxnz(1);
                            break;
                        }else {
                            ipage.getRecords().get(i).setSfnjxnz(0);
                        }
                    }
                    if (ipage.getRecords().get(i).getSfnjxnz()==0){
                        QueryWrapper<YwGdxxCljl> queryWrapper3=new QueryWrapper<>();
                        queryWrapper3.eq("gdxx_id",ywGdxx.getId());
                        queryWrapper3.orderByDesc("id");
                        List<YwGdxxCljl> ywGdxxCljls = ywGdxxCljlMapper.selectList(queryWrapper3);
                        if (ywGdxxCljls.size()>0){
                            YwGdxxCljl ywGdxxCljl = ywGdxxCljls.get(0);
                            if (ywGdxxCljl.getJdygId().compareTo(UserThreadLocal.get().getId())==0 && ywGdxxCljl.getAuditState()==0){
                                ipage.getRecords().get(i).setSfnjxnz(1);
                            }else {

                            }
                        }
                    }


                }else {
                    ipage.getRecords().get(i).setSfnjxnz(0);
                }

            }
            Long jsnzrId = ywGdxx.getJsnzrId();
            if (!exists){
                if (cxsfwfzr>0){
                    QueryWrapper<YwGdxxCljl> queryWrapper1=new QueryWrapper<>();
                    queryWrapper1.eq("gdxx_id",ywGdxx.getId());
                    queryWrapper1.orderByDesc("id");
                    List<YwGdxxCljl> ywGdxxCljls = ywGdxxCljlMapper.selectList(queryWrapper1);


                    if (ywGdxxCljls.size()>0){
                        YwGdxxCljl ywGdxxCljl = ywGdxxCljls.get(0);
                        if (ywGdxxCljl.getJdygId().compareTo(UserThreadLocal.get().getId())==0 && ywGdxxCljl.getAuditState()==0){
                            ipage.getRecords().get(i).setSfngbj(1);
                        }else {
                            ipage.getRecords().get(i).setSfngbj(0);
                        }
                    }else {
                        ipage.getRecords().get(i).setSfngbj(1);
                    }


                }else {
                    ipage.getRecords().get(i).setSfngbj(0);
                }
            }else {
                if (jsnzrId!=null && UserThreadLocal.get().getId().compareTo(jsnzrId)==0) {
                    if (ywGdxx.getNzzt()==0){
                        ipage.getRecords().get(i).setSfngbj(1);
                    }else{
                        ipage.getRecords().get(i).setSfngbj(0);
                    }

                }else {
                    ipage.getRecords().get(i).setSfngbj(0);

                }
            }

            if (ywGdxx.getFzrAuditState()==0){
                if (cxsfwfzr>0){
                    ipage.getRecords().get(i).setSfngsh(1);
                }else {
                    ipage.getRecords().get(i).setSfngsh(0);
                }
            }
            if (ywGdxx.getFzrAuditState()==1 && ywGdxx.getZzAuditState()==0){
                if (cxsfwzz>0){
                    ipage.getRecords().get(i).setSfngsh(1);
                }else {
                    ipage.getRecords().get(i).setSfngsh(0);
                }
            }
            if (ipage.getRecords().get(i).getZzAuditUserZw()==null){
                ipage.getRecords().get(i).setZzAuditUserZw("站长");
            }
//            Long slrId = ywGdxx.getSlrId();
            Long clrId = ywGdxx.getClrId();
            Long clslrId = ywGdxx.getClslrId();

            if (clrId==null && clslrId==null){
                List<User> cxdqzbry = ywZbglGlryMapper.cxzbry(ywGdxx.getId());
                ipage.getRecords().get(i).setSfngclgd(0);
                for (int j = 0; j < cxdqzbry.size(); j++) {
                    User user = cxdqzbry.get(j);
                    if (user.getJjbType()!=null && (user.getJjbType()==1 || user.getJjbType()==3)){
                        if (user.getId().compareTo(UserThreadLocal.get().getId())==0){
                            if (ywGdxx.getHxzt()!=null && (ywGdxx.getHxzt()==3 || ywGdxx.getHxzt()==99)){
                                ipage.getRecords().get(i).setSfngclgd(0);
                            }else {
                                if (ywGdxx.getSlcs()==null){
                                    ipage.getRecords().get(i).setSfngclgd(1);
                                }else {
                                    if (user.getJjbType()==1){
                                        ipage.getRecords().get(i).setSfngclgd(1);
                                    }else{
                                        ipage.getRecords().get(i).setSfngclgd(0);
                                    }
                                }
                            }


                            break;
                        }
                    }
                }
            }else {
                ipage.getRecords().get(i).setSfngclgd(0);
                QueryWrapper<YwGdxxClNzjl> queryWrapper1=new QueryWrapper<>();
                queryWrapper1.eq("gdxx_id",ywGdxx.getId());
                queryWrapper1.orderByDesc("id");
                List<YwGdxxClNzjl> ywGdxxClNzjls = ywGdxxClNzjlMapper.selectList(queryWrapper1);
                if (ywGdxxClNzjls==null || ywGdxxClNzjls.size()==0){
                    if (clrId.compareTo(UserThreadLocal.get().getId())==0){
                        ipage.getRecords().get(i).setSfngclgd(1);
                        break;
                    }
                }else {
                    for (int j = 0; j < ywGdxxClNzjls.size(); j++) {
                        YwGdxxClNzjl ywGdxxClNzjl = ywGdxxClNzjls.get(j);
                        if (ywGdxxClNzjl.getAuditState()==1 && (ywGdxx.getHxzt()==2 ||  ywGdxx.getHxzt()==4)){
                            if (ywGdxxClNzjl.getNzrId().compareTo(UserThreadLocal.get().getId())==0){
                                ipage.getRecords().get(i).setSfngclgd(1);
                                break;
                            }else {
                                break;
                            }

                        }else {
                            break;
                        }
                    }
                }

            }

            if (clrId!=null){
                ipage.getRecords().get(i).setSfngzjgd(0);
                QueryWrapper<YwGdxxClNzjl> queryWrapper1=new QueryWrapper<>();
                queryWrapper1.eq("gdxx_id",ywGdxx.getId());
                queryWrapper1.orderByDesc("id");
                List<YwGdxxClNzjl> ywGdxxClNzjls = ywGdxxClNzjlMapper.selectList(queryWrapper1);
                if (ywGdxxClNzjls==null || ywGdxxClNzjls.size()==0){
                    if (clrId.compareTo(UserThreadLocal.get().getId())==0){
                        ipage.getRecords().get(i).setSfngzjgd(1);
                        break;
                    }
                }else {
                    for (int j = 0; j < ywGdxxClNzjls.size(); j++) {
                        YwGdxxClNzjl ywGdxxClNzjl = ywGdxxClNzjls.get(j);
                        if (ywGdxxClNzjl.getAuditState()==1){
                            if (ywGdxxClNzjl.getNzrId().compareTo(UserThreadLocal.get().getId())==0){
                                ipage.getRecords().get(i).setSfngzjgd(1);
                                break;
                            }else {
                                break;
                            }

                        }else {
                            break;
                        }
                    }
                }
            }else{
                ipage.getRecords().get(i).setSfngzjgd(0);
                if ((clslrId!=null && clslrId.compareTo(UserThreadLocal.get().getId())==0) || (ywGdxx.getSlrId()!=null && ywGdxx.getSlrId().compareTo(UserThreadLocal.get().getId())==0)){
                    if (ywGdxx.getNzzt()==0){
                        ipage.getRecords().get(i).setSfngzjgd(1);
                    }

                }

            }
//            ipage.getRecords().get(i).setSfngbj(ipage.getRecords().get(i).getSfngzjgd());

//            if (ipage.getRecords().get(i).getSfngbj()==1){
//                ipage.getRecords().get(i).setSfngzjgd(0);
//            }
            if (ipage.getRecords().get(i).getSfnjxnz()==1){
                ipage.getRecords().get(i).setSfngbj(1);
            }

        }
        return ipage;
    }

    @Override
    public List<YwGdxxDochuDto> daochu(YwGdxxVo vo) {
        vo.setPage(1);
        vo.setSize(1000);
        IPage<YwGdxx> page = page(vo);
        List<YwGdxx> records = page.getRecords();

        List<YwGdxxDochuDto> list=new ArrayList<>();
        for (int i = 0; i < records.size(); i++) {
            YwGdxx ywGdxx = records.get(i);

            YwGdxxDochuDto ywGdxxDochuDto=new YwGdxxDochuDto();
            ywGdxxDochuDto.setId(i+1+"");
            ywGdxxDochuDto.setGdlxName(ywGdxx.getGdlxName());
            ywGdxxDochuDto.setNyzName(ywGdxx.getNyzName());
            ywGdxxDochuDto.setFzrName(ywGdxx.getFzrName());
            ywGdxxDochuDto.setWtms(ywGdxx.getWtms());
            String state="";
            switch (ywGdxx.getState()){
                case 0:
                    state="审核中";
                    break;
                case 1:
                    state="审核通过";
                    break;
                case 2:
                    state="审核不通过";
                    break;
            }

            String hxzt="待受理";
            if (ywGdxx.getHxzt()!=null){
                switch (ywGdxx.getHxzt()){
                    case 1:
                        hxzt="已受理，待处理";
                        break;
                    case 2:
                        hxzt="已处理，待办结";
                        break;
                    case 3:
                        hxzt="拒绝办结，待处理";
                        break;
                    case 4:
                        hxzt="已办结";
                        break;
                    default:
                        hxzt="待受理";
                }
            }

            ywGdxxDochuDto.setState(state);
            ywGdxxDochuDto.setHxzt(hxzt);
            ywGdxxDochuDto.setCreateTime(DateTimeUtil.getStrDateTime3(ywGdxx.getCreateTime()));
            list.add(ywGdxxDochuDto);
        }

        return list;
    }

    @Override
    public YwGdxx get(Long id) {
        YwGdxxVo vo=new YwGdxxVo();
        vo.setId(id);
        IPage<YwGdxx> ipage=new Page<>(1,1);
        ywGdxxMapper.page(ipage,vo);
        YwGdxx ywGdxx = ipage.getRecords().get(0);

        List<YwZbglGlry> all1 = ywZbglGlryMapper.all(ywGdxx.getId(), 1,4);
        List<YwZbglGlry> all3 = ywZbglGlryMapper.all(ywGdxx.getId(), 3,4);
        if (all1!=null && all1.size()>0){
            ywGdxx.setZbfzr(all1.get(0).getUserName());
        }
        String aaa="";
        for (int j = 0; j < all3.size(); j++) {
            if (j==0){
                aaa=all3.get(j).getUserName();
            }else {
                aaa+=","+all3.get(j).getUserName();
            }
        }
        ywGdxx.setZbry(aaa);

        if (ywGdxx.getZzAuditUserZw()==null){
            ywGdxx.setZzAuditUserZw("站长");
        }

        return ywGdxx;
    }

    @Override
    public void getDaochu(YwGdxx ywGdxx, HttpServletResponse response) {
        YwGdxxCljl ywGdxxCljl =new YwGdxxCljl();
        ywGdxxCljl.setId(ywGdxx.getId());
        YwGdxxCljl zxjl = ywGdxxCljlService.zxjl(ywGdxxCljl);

        // 定义全局的字体静态变量
        //定义全局字体静态变量
        Font titlefont;
        Font headfont = null;
        Font headfont1 = null;
        Font keyfont = null;
        Font textfont = null;
        Font textfont1 = null;
        Font content = null;
        Font space = null;
        Font space1 = null;
        Font space2 = null;
        Font space3 = null;
        // 最大宽度
        try {
            // 不同字体（这里定义为同一种字体：包含不同字号、不同style）
            BaseFont font = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            titlefont = new Font(font, 16, Font.BOLD);
            //四号
            headfont = new Font(font, 14, Font.BOLD);
            headfont1 = new Font(font, 14, Font.NORMAL);
            //三号
            content = new Font(font, 16, Font.NORMAL);
            //小四
            textfont = new Font(font, 11, Font.BOLD);
            textfont1 = new Font(font, 11, Font.NORMAL);
            space = new Font(font, 2, Font.NORMAL);
            space1 = new Font(font, 10, Font.NORMAL);
            space2 = new Font(font, 30, Font.NORMAL);
            space3 = new Font(font, 20, Font.NORMAL);
        } catch (Exception e) {
            e.printStackTrace();
        }
        BaseFont bf;
        Font font = null;
        try {
            //创建字体
            bf = BaseFont.createFont( "STSong-Light", "UniGB-UCS2-H",
                    BaseFont.NOT_EMBEDDED);
            //使用字体并给出颜色
            font = new Font(bf,20,Font.BOLD, BaseColor.BLACK);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Document document = new Document(new RectangleReadOnly(842F, 595F));
        //设置页边距  60:左边距，60：右边距，72：上边距，72：下边距
        document.setMargins(60, 60, 72, 72);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
            PdfPCell cell = null;
            //添加页码
            writer.setPageEvent(new PdfPageUtil());
            //打开生成的pdf文件
            document.open();



            //交接班信息
            float[] widthes = {30f};
            PdfPTable tables = new PdfPTable(widthes);


            widthes = new float[]{20f, 20f, 20f, 20f, 20f, 20f, 20f, 20f};
            //PdfPTable tables = new PdfPTable(widthess);
            // tables = new PdfPTable(widthess);
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);


            cell = new PdfPCell(new Paragraph("所属站点:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);
            String aaa="aaa";

            cell = new PdfPCell(new Paragraph(ywGdxx.getNyzName(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("申请人:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(ywGdxx.getSqrName(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("工单类型:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);


            cell = new PdfPCell(new Paragraph(ywGdxx.getGdlxName(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("最晚受理时间:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);


            cell = new PdfPCell(new Paragraph(DateTimeUtil.getStrDateTime3(ywGdxx.getZwslsjTime()),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            document.add(tables);


            //负责人
            widthes = new float[]{20f, 20f, 20f, 20f, 20f, 20f};
            //PdfPTable tables = new PdfPTable(widthess);
            // tables = new PdfPTable(widthess);
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);


            cell = new PdfPCell(new Paragraph("负责人:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(ywGdxx.getFzrName(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("运维人员:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(ywGdxx.getZbry(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("所在位置:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);


            cell = new PdfPCell(new Paragraph(ywGdxx.getSzwz(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            document.add(tables);



            //处理信息
            widthes = new float[]{10f,90f};
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);

            cell = new PdfPCell(new Paragraph("问题描述",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(ywGdxx.getWtms(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);


            document.add(tables);



//            widthes = new float[]{20f, 20f, 20f, 20f, 20f, 20f, 20f, 20f};
//            //PdfPTable tables = new PdfPTable(widthess);
//            // tables = new PdfPTable(widthess);
//            tables = new PdfPTable(widthes);
//            tables.setSpacingBefore(10f);
//            tables.setWidthPercentage(100.0f);
//
//            cell = new PdfPCell(new Paragraph("负责人:",textfont));
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//            cell.setFixedHeight(30);
//            cell.setBorder(0);
//            tables.addCell(cell);
//
//            cell = new PdfPCell(new Paragraph(aaa,textfont));
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//            cell.setFixedHeight(30);
//            cell.setBorder(0);
//            tables.addCell(cell);
//            document.add(tables);
//
//
//            cell = new PdfPCell(new Paragraph("运维人员:",textfont));
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//            cell.setFixedHeight(30);
//            cell.setBorder(0);
//            tables.addCell(cell);
//
//            cell = new PdfPCell(new Paragraph(aaa,textfont));
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//            cell.setFixedHeight(30);
//            cell.setBorder(0);
//            tables.addCell(cell);
//
//            cell = new PdfPCell(new Paragraph("所在位置:",textfont));
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//            cell.setFixedHeight(30);
//            cell.setBorder(0);
//            tables.addCell(cell);
//
//            cell = new PdfPCell(new Paragraph(aaa,textfont));
//            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//            cell.setFixedHeight(30);
//            cell.setBorder(0);
//            tables.addCell(cell);
//
//            document.add(tables);


            //负责人信息审核
            widthes = new float[]{30f};
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);

            cell = new PdfPCell(new Paragraph("负责人信息审核",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);


            document.add(tables);


            widthes = new float[]{20f, 30f, 20f, 20f, 20f, 20f, 20f, 30f};
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);


            cell = new PdfPCell(new Paragraph("审核账号:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(ywGdxx.getFzrAuditUserName(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("人员职位:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);


            cell = new PdfPCell(new Paragraph(ywGdxx.getFzrAuditUserZw(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("审核状态:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);

            switch (ywGdxx.getFzrAuditState()){
                case 0:
                    aaa="审核中";
                    break;
                case 1:
                    aaa="审核通过";
                    break;
                case 2:
                    aaa="驳回";
                    break;

            }
            cell = new PdfPCell(new Paragraph(aaa,textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("审核时间:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(DateTimeUtil.getStrDateTime(ywGdxx.getFzrAuditTime()),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            document.add(tables);


            //站长审核
            widthes = new float[]{30f};
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);

            cell = new PdfPCell(new Paragraph("站长信息审核",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);


            document.add(tables);


            widthes = new float[]{20f, 30f, 20f, 20f, 20f, 20f, 20f, 30f};
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);


            cell = new PdfPCell(new Paragraph("审核账号:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(ywGdxx.getZzAuditUserName(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("人员职位:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);


            cell = new PdfPCell(new Paragraph(ywGdxx.getZzAuditUserZw(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("审核状态:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);

            switch (ywGdxx.getZzAuditState()){
                case 0:
                    aaa="审核中";
                    break;
                case 1:
                    aaa="审核通过";
                    break;
                case 2:
                    aaa="驳回";
                    break;

            }
            cell = new PdfPCell(new Paragraph(aaa,textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("审核时间:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(DateTimeUtil.getStrDateTime(ywGdxx.getZzAuditTime()),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            document.add(tables);


            //处理信息
            widthes = new float[]{30f};
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);

            cell = new PdfPCell(new Paragraph("处理信息",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);


            document.add(tables);


            widthes = new float[]{20f, 20f, 20f, 20f, 20f, 20f};
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);


            cell = new PdfPCell(new Paragraph("接单员工:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(zxjl.getJdygName(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("接单时间:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);


            cell = new PdfPCell(new Paragraph(DateTimeUtil.getStrDateTime(zxjl.getJdsjTime()),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph("联系电话:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setFixedHeight(30);
            tables.addCell(cell);

            cell = new PdfPCell(new Paragraph(zxjl.getLxdh(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            document.add(tables);

            //未处理故障
            widthes = new float[]{10f,90f};
            //PdfPTable tables = new PdfPTable(widthess);
            // tables = new PdfPTable(widthess);
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);

            cell = new PdfPCell(new Paragraph("处理意见:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);


            cell = new PdfPCell(new Paragraph(zxjl.getClxxwz(),textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);
            document.add(tables);





            widthes = new float[]{30f};
            tables = new PdfPTable(widthes);
            tables.setSpacingBefore(10f);
            tables.setWidthPercentage(100.0f);

            cell = new PdfPCell(new Paragraph("处理图片:",textfont));
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setFixedHeight(30);
            cell.setBorder(0);
            tables.addCell(cell);

            document.add(tables);

            List<String> zh = urlConvertUtil.zh(zxjl.getClxxtp());

            if (zh.size()>0){
                PdfPTable table = new PdfPTable(zh.size()); // 3 columns for 3 images in a row
                table.setWidthPercentage(100); // Set the width of the table to 100% of the page width

                //故障图片上传
                for (int i = 0; i < zh.size(); i++) {
                    String s = zh.get(i);
                    Image image = Image.getInstance(s); // 替换为你的图片路径
                    // 设置图片大小
                    float imageWidth = 10f; // 设置图片的宽度
                    float imageHeight = image.getScaledHeight() * (imageWidth / image.getScaledWidth()); // 根据宽度计算高度
                    image.setAlignment(Image.ALIGN_LEFT); // 设置图片居中
                    image.scaleAbsolute(imageWidth, imageHeight); // 设置图片的绝对大小
                    image.setIndentationLeft(20f);

                    cell = new PdfPCell();
                    cell.setImage(image);
                    table.addCell(cell);
                }
                document.add(table);
            }


            document.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void sl(YwGdxx ywGdxx) {
        YwGdxx sl = ywGdxxMapper.selectById(ywGdxx);
        if (sl!=null ){
            Long userId = UserThreadLocal.get().getId();
            sl.setHxzt(2);
            sl.setSlrId(userId);
            ywGdxxMapper.updateById(sl);

            YwGdxxCljl ywGdxxCljl=new YwGdxxCljl();
            String phone = UserThreadLocal.get().getPhone();
            ywGdxxCljl.setGdxxId(sl.getId());
            ywGdxxCljl.setJdygId(userId);
            ywGdxxCljl.setJdsjTime(DateTimeUtil.dqsj());
            ywGdxxCljl.setLxdh(phone);
            ywGdxxCljl.setAuditState(0);
            ywGdxxCljlMapper.insert(ywGdxxCljl);

            QueryWrapper<YwBjgl> queryWrapper=new QueryWrapper<>();
            queryWrapper.eq("gd_id",sl.getId());
            YwBjgl ywBjgl = ywBjglMapper.selectOne(queryWrapper);
            if (ywBjgl!=null){
                ywBjgl.setBjzt(1);
                ywBjglMapper.updateById(ywBjgl);
            }

        }
    }

    @Override
    public void bj(YwGdxx ywGdxx) {
        YwGdxx sl = ywGdxxMapper.selectById(ywGdxx);
        if (sl!=null ){
            if (ywGdxx.getHxzt()==99){
                sl.setHxzt(99);
            }else {
                sl.setHxzt(4);

                YwGdxxCljl ywGdxxCljl=new YwGdxxCljl();
                Long userId = UserThreadLocal.get().getId();
                String phone = UserThreadLocal.get().getPhone();
                ywGdxxCljl.setGdxxId(sl.getId());
                ywGdxxCljl.setJdygId(userId);
                ywGdxxCljl.setJdsjTime(DateTimeUtil.dqsj());
                ywGdxxCljl.setLxdh(phone);
                ywGdxxCljl.setAuditState(0);
                ywGdxxCljlMapper.insert(ywGdxxCljl);
            }

            ywGdxxMapper.updateById(sl);


        }
    }

    @Override
    public void yj(YwGdxx ywGdxx) {
        YwGdxx yj = ywGdxxMapper.selectById(ywGdxx);
//        if (yj.getHxzt()!=null){
//            throw new MyException("状态错误,移交失败");
//        }
        if (yj != null) {
            yj.setSlrId(ywGdxx.getSlrId());
            ywGdxxMapper.updateById(yj);
            QueryWrapper<YwGdxxCljl> queryWrapper=new QueryWrapper<>();
            queryWrapper.eq("gdxx_id",yj.getId());
            List<YwGdxxCljl> ywGdxxCljls = ywGdxxCljlMapper.selectList(queryWrapper);
            for (int i = 0; i < ywGdxxCljls.size(); i++) {
                YwGdxxCljl ywGdxxCljl = ywGdxxCljls.get(i);
                ywGdxxCljl.setJdygId(ywGdxx.getSlrId());
                ywGdxxCljlMapper.updateById(ywGdxxCljl);
            }
        }
    }

    @Override
    public List<Map<String, Object>> ccggry(Long id) {
        List<Map<String, Object>> ccggry = ywGdxxMapper.ccggry(id);
        YwGdxx ywGdxx = ywGdxxMapper.selectById(id);
        Long nyzId = ywGdxx.getNyzId();
        PageVo vo=new PageVo();
        vo.setParentId(nyzId);
        vo.setPage(1);
        vo.setSize(1000);
        IPage<SiteHeaderToUser> siteHeaderToUserIPage = organizationalStructureService.siteHeaderExamineList(vo);
        for (int i = 0; i < siteHeaderToUserIPage.getRecords().size(); i++) {
            List<SiteHeaderToUser> records = siteHeaderToUserIPage.getRecords();
            SiteHeaderToUser siteHeaderToUser = records.get(i);
            Map<String, Object> map=new HashMap<>();
            map.put("id",siteHeaderToUser.getId());
            map.put("nickname",siteHeaderToUser.getNickname());
            map.put("phone",siteHeaderToUser.getPhone());
            ccggry.add(map);
        }
        return ccggry;
    }



    @Override
    public List<Map<String, Object>> ccggry1(Long id) {
        YwGdxx ywGdxx = ywGdxxMapper.selectById(id);
        List<Map<String, Object>> ccggry = ywGdxxMapper.ccggry1(UserThreadLocal.get().getId(),ywGdxx.getNyzId());
//        Long nyzId = ywGdxx.getNyzId();
//        PageVo vo=new PageVo();
//        vo.setParentId(nyzId);
//        vo.setPage(1);
//        vo.setSize(1000);
//        IPage<SiteHeaderToUser> siteHeaderToUserIPage = organizationalStructureService.siteHeaderExamineList(vo);
//        for (int i = 0; i < siteHeaderToUserIPage.getRecords().size(); i++) {
//            List<SiteHeaderToUser> records = siteHeaderToUserIPage.getRecords();
//            SiteHeaderToUser siteHeaderToUser = records.get(i);
//            Map<String, Object> map=new HashMap<>();
//            map.put("id",siteHeaderToUser.getId());
//            map.put("nickname",siteHeaderToUser.getNickname());
//            map.put("phone",siteHeaderToUser.getPhone());
//            ccggry.add(map);
//        }
        return ccggry;
    }

    @Override
    public List<Map<String, Object>> ccggry2(Long id) {
        YwGdxx ywGdxx = ywGdxxMapper.selectById(id);
        QueryWrapper<YwGdxxNzjl> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("gdxx_id",ywGdxx.getId());
        queryWrapper.orderByDesc("id");
        List<YwGdxxNzjl> ywGdxxNzjls = ywGdxxNzjlMapper.selectList(queryWrapper);
        Long nzrId=null;
        if (ywGdxxNzjls.size()>0){
            nzrId = ywGdxxNzjls.get(0).getNzrId();
        }

        List<Map<String, Object>> ccggry = ywGdxxMapper.ccggry2(UserThreadLocal.get().getId(),ywGdxx.getNyzId());
        Long nyzId = ywGdxx.getNyzId();
        PageVo vo=new PageVo();
        vo.setParentId(nyzId);
        vo.setPage(1);
        vo.setSize(1000);
        IPage<SiteHeaderToUser> siteHeaderToUserIPage = organizationalStructureService.siteHeaderExamineList(vo);
        for (int i = 0; i < siteHeaderToUserIPage.getRecords().size(); i++) {
            List<SiteHeaderToUser> records = siteHeaderToUserIPage.getRecords();
            SiteHeaderToUser siteHeaderToUser = records.get(i);
            if (UserThreadLocal.get().getId().compareTo(siteHeaderToUser.getId())!=0){
                Map<String, Object> map=new HashMap<>();
                map.put("id",siteHeaderToUser.getId());
                map.put("nickname",siteHeaderToUser.getNickname());
                map.put("phone",siteHeaderToUser.getPhone());
                ccggry.add(map);
            }
        }
        return ccggry;
    }
    @Override
    public void addQuestion(YwGdxx ywGdxx) {
        Long userId = UserThreadLocal.get().getId();
        ywGdxx.setSqrId(userId);
        ywGdxx.setFzrAuditState(1);
        ywGdxx.setZzAuditState(1);
        ywGdxx.setState(1);
        ywGdxx.setNzzt(0);
        ywGdxx.setHxzt(2);
        ywGdxxMapper.insert(ywGdxx);
        InspectionItemManagementExtend extend = inspectionItemManagementExtendMapper.selectById(ywGdxx.getXjxId());
        extend.setGdId(ywGdxx.getId());
        inspectionItemManagementExtendMapper.updateById(extend);
        QueryWrapper<YwZbglGlry> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("gl_id",ywGdxx.getXqId());
        List<YwZbglGlry> ywZbglGlries = ywZbglGlryMapper.selectList(queryWrapper);
        for (int i = 0; i < ywZbglGlries.size(); i++) {
            YwZbglGlry ywZbglGlry = ywZbglGlries.get(i);
            ywZbglGlry.setId(null);
            ywZbglGlry.setFl(4);
            ywZbglGlry.setGlId(ywGdxx.getId());
            ywZbglGlryMapper.insert(ywZbglGlry);
        }
    }
}
